import { createApp } from "vue";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router/index";
import store from "./store";
import {myVueplugin} from "./plugins/myVueplugin";
import { myVuethrottle } from "./plugins/myVuethrottle";
import { myVueDebounce } from "./plugins/myVueDebounce";
import VituaList from "./components/VituaList.vue";
const app = createApp(App);

// 按钮权限指令
app.directive("auth", {
  mounted(el, binding) {
    const userAuths = store.state.userPermissions
      ? store.state.userPermissions
      : [];
    // el 指令绑定的真实dom元素
    // binding 指令的绑定对象
    const bthAuth = binding.value;
    const hasAuth = userAuths
      .map((auth: { action: any }) => auth.action)
      .includes(bthAuth);
    if (!hasAuth) {
      // 权限不足，移除该元素
      el.remove();
    }
  },
});

app.use(router);
app.use(myVueDebounce);
app.use(myVuethrottle);
app.use(myVueplugin);
app.use(ElementPlus);
app.use(store);
app.component("VituaList", VituaList);
app.mount("#app");
